package com.mysoft.gfyx.clue.controller;

import com.mysoft.framework.modeling.dataapi.DataApi;
import com.mysoft.framework.mvc.api.Controller;
import com.mysoft.framework.rpc.annotation.PubAction;
import com.mysoft.framework.rpc.annotation.PubService;
import com.mysoft.framework.rpc.contants.RequestPrefix;
import com.mysoft.gfyx.clue.controller.dto.Subscription.AddRadarSubscriptionRequestDto;
import com.mysoft.gfyx.clue.controller.dto.Subscription.GetSubscriptionConfigRequestDto;
import com.mysoft.gfyx.clue.controller.dto.Subscription.GetWxQrCodeRequestDto;
import com.mysoft.gfyx.clue.service.SubscriptionService;
import com.mysoft.gfyx.clue.service.dto.QrCodeDataDto;
import com.mysoft.gfyx.common.util.LogUtil;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMethod;

@PubService(value = "/subscriptionDataApi", prefix = RequestPrefix.API)
@Tag(name = "订阅管理-API")
public class SubscriptionDataApiController extends Controller implements DataApi {
    @Autowired
    private SubscriptionService subscriptionService;

    @Autowired
    private LogUtil logUtil;

    @Tag(name = "应用当前配置到调度")
    @PubAction(value = "/applyCron", method = RequestMethod.POST)
    @ApiOperation(value = "/applyCron", notes = "应用当前配置到调度，后期调度进入开户平台则不再使用")
    public boolean applyCron() {
        return subscriptionService.applyCron();
    }

    @PubAction(value = "/getSubscriptionConfig", method = RequestMethod.POST)
    @ApiOperation(value = "/getSubscriptionConfig", notes = "获取当前用户的订阅配置")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "xxx", value = "xxx", paramType = "query", dataType = "String", required = true)
    })
    public Object getSubscriptionConfig(@RequestBody GetSubscriptionConfigRequestDto getSubscriptionConfigRequestDto) {
        return subscriptionService.getMySubscription(getSubscriptionConfigRequestDto.getType());
    }

    @PubAction(value = "/isSetAdminSubscription", method = RequestMethod.POST)
    @ApiOperation(value = "/isSetAdminSubscription", notes = "保存bu的区域权限，并且将权限给到一批用户")
    public Object isSetAdminSubscription() {
        return subscriptionService.isSetAdminSubscription();
    }

    @PubAction(value = "/getWxQrCode", method = RequestMethod.POST)
    public QrCodeDataDto getWxQrCode() {
        return subscriptionService.getWxQrCode();
    }

    @PubAction(value = "/getBindStatus", method = RequestMethod.POST)
    public QrCodeDataDto getBindStatus(@RequestBody GetWxQrCodeRequestDto getWxQrCodeRequestDto) {
        return subscriptionService.getBindStatus(getWxQrCodeRequestDto);
    }

    @PubAction(value = "/addRadarSubscription", method = RequestMethod.POST)
    @ApiOperation(value = "/addRadarSubscription", notes = "添加线索订阅")
    public Boolean addRadarSubscription(@RequestBody AddRadarSubscriptionRequestDto dto) {
        return subscriptionService.addRadarSubscription(dto);
    }

    @PubAction(value = "/syncSubscription", method = RequestMethod.POST)
    @ApiOperation(value = "/syncSubscription", notes = "一键同步线索订阅")
    public Boolean syncSubscription(@RequestBody GetSubscriptionConfigRequestDto getSubscriptionConfigRequestDto) {
        return subscriptionService.syncSubscription(getSubscriptionConfigRequestDto.getType());
    }
}